/**
 * @projectName: project02bywdmtz
 * @package: com.cskaoyan.controller
 * @className: AdminCategoryController
 * @author: 冉夏
 * @description: TODO
 * @date: 2022/12/29 18:55
 * @version: 1.8
 */

package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.bo.CategoryBo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.CategoryLiVo;
import com.cskaoyan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("admin/category")
@RestController
public class AdminCategoryController {
    @Autowired
    CategoryService categoryService;
    /*
    * 获得所有的类目表信息
    * */
    @GetMapping("list")
    public BaseRespVo getAllCategory(){
        CommonData commonData =categoryService.getAllCategoryInfo();
        return BaseRespVo.ok(commonData);
    }
    /*
    * 添加类目
    * */
    @PostMapping("create")
    public BaseRespVo addCategory(@RequestBody MarketCategory categoryBo){
        MarketCategory categoryVo=categoryService.addCategoryInfo(categoryBo);
        return BaseRespVo.ok(categoryVo);
    }
    /*
    * 删除类目 修改状态码0===>1
    * */
    @PostMapping("delete")
    public BaseRespVo deleteCategory(@RequestBody MarketCategory category){
        categoryService.deleteCategoryByClick(category);
        return BaseRespVo.ok(null);
    }
    /*
    * 更新数据
    *
    * */
    @PostMapping("update")
    public  BaseRespVo updateCategory(@RequestBody MarketCategory category){
        categoryService.updateCategory(category);
        return BaseRespVo.ok(null);
    }
    /*
    * 用于商品主类的显示  添加时候用的父接口
    * */
    @GetMapping("l1")
    public BaseRespVo getL1Info(){
        CommonData<CategoryLiVo> commonData=categoryService.getL1InfoShow();
        return BaseRespVo.ok(commonData);
    }


}
